package com.resource.coursemanage.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.resource.common.utils.AppResponse;
import com.resource.common.utils.R;
import com.resource.coursemanage.entity.TCourseInformationEntity;
import com.resource.coursemanage.entity.TResourceInformationEntity;
import com.resource.coursemanage.service.TResourceInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.resource.common.utils.PageUtils;


/**
 * 教材资源表
 *
 * @author zkx
 * @email 1486664603@qq.com
 * @date 2023-03-06 20:53:55
 */
@RestController
@RequestMapping("course/tresourceinformation")
public class TResourceInformationController {
    @Autowired
    private TResourceInformationService tResourceInformationService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = tResourceInformationService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        TResourceInformationEntity tResourceInformation = tResourceInformationService.getById(id);

        return R.ok().put("tResourceInformation", tResourceInformation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody TResourceInformationEntity tResourceInformation) {
        tResourceInformationService.save(tResourceInformation);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody TResourceInformationEntity tResourceInformation) {
        tResourceInformationService.updateById(tResourceInformation);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        tResourceInformationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    //预览
    @RequestMapping("/review")
    public R studyCourse(@RequestBody List<TResourceInformationEntity> tResourceInformation){
        return tResourceInformationService.reviewResource(tResourceInformation.get(0));
    }

}
